//
//  MHChangeSignViewController.m
//  ManHua
//
//  Created by 江子安 on 15/11/2.
//  Copyright © 2015年 蓝欧科技. All rights reserved.
//

#import "MHChangeSignViewController.h"

@interface MHChangeSignViewController ()<UITextViewDelegate>

@property (nonatomic, strong) UITextView *signView;
@property (nonatomic, strong) UILabel *countLabel;

@end

@implementation MHChangeSignViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"个性签名";
    
    
    self.signView = [[UITextView alloc]initWithFrame:CGRectMake(10, 94, Width - 20, 120)];
    self.signView.layer.borderWidth = 0.5;
    self.signView.layer.cornerRadius = 10;
    self.signView.layer.borderColor = [[UIColor lightGrayColor] CGColor];
    self.automaticallyAdjustsScrollViewInsets = NO;
    _signView.backgroundColor = [UIColor whiteColor];
    _signView.scrollEnabled = NO;//是否可以拖动

    _signView.font = [UIFont systemFontOfSize:15];
    _signView.delegate = self;
    _signView.text = self.userInfo.UserOther;
    
    _countLabel = [[UILabel alloc]initWithFrame:CGRectMake(Width - 60, 90, 40, 30)];
    _countLabel.text = @"100";
    [_signView addSubview:_countLabel];
//    [_signView addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];

    
    [self.view addSubview:_signView];
    
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if (range.location>=100)
    {
        //控制输入文本的长度
        return  NO;
    }
    if ([text isEqualToString:@"\n"]) {
        //禁止输入换行
        return NO;
    }
    else
    {

        return YES;
    }
}
/*由于联想输入的时候，函数textView:shouldChangeTextInRange:replacementText:无法判断字数，
 因此使用textViewDidChange对TextView里面的字数进行判断
 */
- (void)textViewDidChange:(UITextView *)textView
{
    //该判断用于联想输入
    if (textView.text.length > 100)
    {
        textView.text = [textView.text substringToIndex:100];
    }
     _countLabel.text = [NSString stringWithFormat:@"%ld", 100 - textView.text.length];
    _sign = textView.text;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
